package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.Prize;
import cn.tedu.lucky.draw.server.protocol.query.PrizeQuery;
import cn.tedu.lucky.draw.server.service.IPrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class PrizeController {

    @Autowired
    private IPrizeService prizeService;

    @PostMapping("/draw/prize/findAll")
    public JsonResult<List<Prize>> findAll(@RequestBody PrizeQuery prizeQuery){
        List<Prize> prizeList = prizeService.findAll(prizeQuery);
        return JsonResult.ok(prizeList);
    }


    /**
     * 新增奖品
     */
    @PostMapping("/draw/prize/save")
    public JsonResult<String> add(@RequestBody Prize prize) {
        prizeService.save(prize);
        return JsonResult.ok("新增奖品成功");
    }

    @GetMapping("/draw/prize/findPrize/{id}")
    public JsonResult<List<Prize>> findPrizeActivityId(@PathVariable("id") Long id){
        List<Prize> prizeList = prizeService.findAllByActivityId(id);
        return JsonResult.ok(prizeList);
    }

    @GetMapping("/draw/price/noBindPrize/{id}")
    public JsonResult<List<Prize>> findNoBindPrizeByActivityId(@PathVariable("id") Long id){
        List<Prize> prizeList = prizeService.findNoBindPrizeByActivityId(id);
        return JsonResult.ok(prizeList);
    }

}
